<template>
  <div class="dashboard-editor-container">

    <panel-group @handleSetLineChartData="handleSetLineChartData" :key="componentKey"/>

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:10px;border: 1px solid gray; margin-top: 10px;">
      <line-chart :style="{'height':'300px','width':'100%'}" :key="componentKey"/>
    </el-row>

    <el-row :gutter="32" style="margin-left: 0px;margin-right: 0px;">

      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <pie-chart title="在线统计" :project="['男','女']" :data="piedata.onlineUser"
                     :style="{'height':'200px','width':'100'}" unit="人"></pie-chart>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <pie-chart title="流水统计" :project="['充值','提现']" :data="piedata.settle"
                     :style="{'height':'200px','width':'100%'}" unit="元"></pie-chart>
        </div>
      </el-col>
      <el-col :xs="24" :sm="24" :lg="8">
        <div class="chart-wrapper">
          <pie-chart title="通话统计" :project="['已接通','未接通']" :data="piedata.call"
                     :style="{'height':'200px','width':'100%'}" unit="次"></pie-chart>
        </div>
      </el-col>
    </el-row>


  </div>
</template>

<script>
import PanelGroup from './dashboard/PanelGroup'
import LineChart from './dashboard/LineChart'
import RaddarChart from './dashboard/RaddarChart'
import PieChart from './dashboard/PieChart'
import BarChart from './dashboard/BarChart'
import {indexPie} from "@/api/service/index/analyse";


export default {
  name: 'Index',
  components: {
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart
  },
  data() {
    return {
      piedata: {},
      componentKey: 0,
    }
  },
  mounted() {
    this.getIndexPie();
    setInterval(() => {
      this.componentKey += 1;
      this.getIndexPie();
    }, 1000 * 60);
    // 5秒后重新加载页面
  },
  methods: {
    reloadPage() {
      window.location.reload();
    },
    handleSetLineChartData(url) {
      this.$router.push(url);
    },
    getIndexPie() {
      this.loading = true;
      indexPie({}).then(response => {
        this.piedata = response.data
      });
    },
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding-top: 10px;
  padding-left: 32px;
  padding-right: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width: 1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
